package com.example.uiclassassignments.Activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import com.example.uiclassassignments.R;

@SuppressLint("Registered")
public class PopupWindowActivity extends Activity implements View.OnClickListener {
    private PopupWindow popupWindow;
    LinearLayout ll;
    ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_window);
        ll=findViewById(R.id.ll);
        Button btn_win = findViewById(R.id.btn_win);
        btn_win.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        LayoutInflater layoutInflater=LayoutInflater.from(this) ;
        @SuppressLint("InflateParams")
        View disView=layoutInflater.inflate(R.layout.activity_popu_windows_item,null);
        popupWindow = new PopupWindow(disView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0));
        final ImageView btn_pop_close= (ImageView) disView.findViewById(R.id.btn_pop_close);
        btn_pop_close.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramView) {
                popupWindow.dismiss();
               /* btn_pop_close.setImageResource(R.mipmap.close_button_pressed);*/
            }
        });
        popupWindow.showAtLocation(ll, 0,0, 50); //设置popwindow显示位置
        popupWindow.setFocusable(true); //获取popwindow焦点
        popupWindow.setOutsideTouchable(true);  //设置popwindow如果点击外面区域，便关闭。
        popupWindow.update();
        popupWindow.isShowing();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }
}
